package com.guojian.common.view;

/**
 * 分页bean(只需要传入totalRows,其他属性可以自动生成)
 * 
 * @author guojian
 *
 */
@SuppressWarnings("unused")
public class PageModel {

	private int currentPage = 1;// 当前页数

	public int totalPages = 0;// 总页数

	private int pageSize = 11;// 每页显示数

	private int totalRows = 0;// 总数据数[必须的参数]

	private int startNum = 0;// 开始记录

	private int endNum = 0;// 结束记录

	private int nextPage = 0;// 下一页

	private int previousPage = 0;// 上一页

	private boolean hasNextPage = false;// 是否有下一页

	private boolean hasPreviousPage = false;// 是否有前一页

	private String rank;

	// 分页需要的参数
	private int page = 1;

	private int rows = 10;

	public String getRank() {
		return rank;
	}

	public void setRank(String rank) {
		this.rank = rank;
	}

	private void initCurrentPage() {
		if (this.currentPage >= totalPages) {
			hasNextPage = false;
			this.currentPage = totalPages;
			this.nextPage = totalPages;
		} else {
			hasNextPage = true;
			this.nextPage = currentPage + 1;
		}

		if (currentPage <= 1) {
			hasPreviousPage = false;
			this.currentPage = 1;
			this.previousPage = 1;
		} else {
			hasPreviousPage = true;
			this.previousPage = currentPage - 1;
		}
	}

	private void initEndNum() {
		this.endNum = this.currentPage * this.pageSize;
		if (endNum >= totalRows) {
			endNum = totalRows;
		}
	}

	private void initStartNum() {
		this.startNum = (currentPage - 1) * pageSize + 1;
	}

	private void initTotalPages() {
		this.totalPages = (totalRows - 1) / pageSize + 1;
	}

	public boolean isHasNextPage() {
		return hasNextPage;
	}

	public boolean isHasPreviousPage() {
		return hasPreviousPage;
	}

	/**
	 * @return the nextPage
	 */
	public int getNextPage() {
		return nextPage;
	}

	/**
	 * @param nextPage
	 *            the nextPage to set
	 */
	public void setNextPage(int nextPage) {
		this.nextPage = nextPage;
	}

	/**
	 * @return the previousPage
	 */
	public int getPreviousPage() {
		return previousPage;
	}

	/**
	 * @param previousPage
	 *            the previousPage to set
	 */
	public void setPreviousPage(int previousPage) {
		this.previousPage = previousPage;
	}

	/**
	 * @return the currentPage
	 */
	public int getCurrentPage() {
		if (this.currentPage >= getTotalPages()) {
			hasNextPage = false;
			this.currentPage = getTotalPages();
			this.nextPage = getTotalPages();
		} else {
			hasNextPage = true;
			this.nextPage = currentPage + 1;
		}

		if (currentPage <= 1) {
			hasPreviousPage = false;
			this.currentPage = 1;
			this.previousPage = 1;
		} else {
			hasPreviousPage = true;
			this.previousPage = currentPage - 1;
		}
		return currentPage;
	}

	/**
	 * @param currentPage
	 *            the currentPage to set
	 */
	public void setCurrentPage(int currentPage) {
		this.currentPage = currentPage;
	}

	/**
	 * @return the pageSize
	 */
	public int getPageSize() {
		return pageSize;
	}

	/**
	 * @param pageSize
	 *            the pageSize to set
	 */
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	/**
	 * @return the totalPages
	 */
	public int getTotalPages() {
		return (totalRows - 1) / pageSize + 1;
	}

	/**
	 * @param totalPages
	 *            the totalPages to set
	 */
	public void setTotalPages(int totalPages) {
		this.totalPages = totalPages;
	}

	/**
	 * @return the totalRows
	 */
	public int getTotalRows() {
		return totalRows;
	}

	/**
	 * @param totalRows
	 *            the totalRows to set
	 */
	public void setTotalRows(int totalRows) {
		this.totalRows = totalRows;
	}

	/**
	 * @param hasNextPage
	 *            the hasNextPage to set
	 */
	public void setHasNextPage(boolean hasNextPage) {
		this.hasNextPage = hasNextPage;
	}

	/**
	 * @param hasPreviousPage
	 *            the hasPreviousPage to set
	 */
	public void setHasPreviousPage(boolean hasPreviousPage) {
		this.hasPreviousPage = hasPreviousPage;
	}

	/**
	 * @return the startNum
	 */
	public int getStartNum() {
		return (currentPage - 1) * pageSize + 1;
	}

	public int getPageUIStartNum() {
		return (page - 1) * rows + 1;
	}

	/**
	 * @param startNum
	 *            the startNum to set
	 */
	public void setStartNum(int startNum) {
		this.startNum = startNum;
	}

	/**
	 * @return endNum
	 */
	public int getEndNum() {
		return this.currentPage * this.pageSize;
	}

	public int getEasyuiEndNum() {
		return page * rows;
	}

	public void setEndNum(int endNum) {
		this.endNum = endNum;
	}

	public int getPage() {
		return page;
	}

	public void setPage(int page) {
		this.page = page;
	}

	public int getRows() {
		return rows;
	}

	public void setRows(int rows) {
		this.rows = rows;
	}

}